﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sinacor.Infra.Core.ProcessManager.Client;
using PSE.ProcessManager.Common.Gateway;
using PSE.ProcessManager.Common.Process;

namespace Sinacor.Process.Bovespa.Distribuicao.Client
{
    [Serializable]
    public class ProcessamentoImportacao : SinacorBaseProcessClient
    {
        #region EventHandler

        public event EventHandler ProcessamentoConcluido;

        #endregion

        #region Construtor

        /// <summary>
        /// Construtor padrão
        /// </summary>
        public ProcessamentoImportacao()
        {
            this.Id = ProcessEntity.Catalog.ProcessamentoImportacao.ProcessID;
        }

        #endregion

        #region Métodos Públicos

        public void ProcessarDistribuicao(ProcessEntity.Parameter.FiltroProcessamentoDistribuicao entity)
        {
            Message<ProcessEntity.Parameter.FiltroProcessamentoDistribuicao> _message = new Message<ProcessEntity.Parameter.FiltroProcessamentoDistribuicao>();
            _message.MessageId = ProcessEntity.Catalog.ProcessamentoImportacao.ProcessarDistribuicao.MessageID;
            _message.ProcessId = this.Id;
            _message.Parameter = entity;
            _message.Operation = ProcessEntity.Catalog.ProcessamentoImportacao.ProcessarDistribuicao.Operation;
            _message.From = "ProcessarDistribuicao";

            this.BeginSendMessage(_message);
        }

        #endregion

        #region Métodos Override

        /// <summary>
        /// OnMessageReceived
        /// </summary>
        /// <param name="message">BaseMessage</param>
        protected override void OnMessageReceived(BaseMessage message)
        {
            if (message.MessageId == ProcessEntity.Catalog.ProcessamentoImportacao.ProcessamentoConcluido.MessageID
                && ProcessamentoConcluido != null)
                ProcessamentoConcluido(this, new EventArgs());
            else
                base.OnMessageReceived(message);
        }

        #endregion
    }
}
